namespace ScrumSprintMonitor.Modules.BuildMonitor.ViewModels
{
	#region #using Directives

	using System.Windows.Media;

	using Infrastructure;

	using Microsoft.Practices.ServiceLocation;

	#endregion

	public class FailedBuildRequesterViewModel : BuildViewModelBase,
	                                             IFailedBuildRequesterViewModel
	{
		static FailedBuildRequesterViewModel()
		{
			var dependsOn = Register<FailedBuildRequesterViewModel>();

			dependsOn.Call(me => me.OnPropertyChanged("IsLastBuildBroken")).OnChanged(me => me.ReportableData.LastBuild.Status);
			dependsOn.Call(me => me.OnPropertyChanged("RequestedFor")).OnChanged(me => me.ReportableData.LastBuild.RequestedFor);
		}

		public FailedBuildRequesterViewModel(IServiceLocator serviceLocator)
			: base(serviceLocator)
		{
		}

		#region IFailedBuildRequesterViewModel Members

		public bool IsLastBuildBroken
		{
			get
			{
				EnsureConnected();
				return (LastBuild != null && (LastBuild.Status == BuildStatus.Failed || LastBuild.Status == BuildStatus.PartiallySucceeded));
			}
		}

		public string RequestedFor
		{
			get
			{
				EnsureConnected();
				return (LastBuild != null ? LastBuild.RequestedFor : string.Empty);
			}
		}

		public Brush BackgroundBrush
		{
			get
			{
				GuardDisposed();
				return Brushes.OrangeRed;
			}
		}

		#endregion
	}
}